﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;

namespace card
{
    public partial class PrintSelectForm : Form
    {
        private string _appSettringName = string.Empty;

        public PrintSelectForm()
        {
            InitializeComponent();
        }

        public PrintSelectForm(System.Drawing.Printing.PrinterSettings.StringCollection collection, string name)
            : this()
        {
            foreach (string sPrinter in collection)//获取所有打印机名称
            {
                listBoxPrinters.Items.Add(sPrinter);
            }
            _appSettringName = name;
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (listBoxPrinters.SelectedItem == null)
            {
                MessageBox.Show("请选择打印机！");
            }
            else
            {
                Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                config.AppSettings.Settings[_appSettringName].Value = listBoxPrinters.SelectedItem.ToString();

                config.Save(ConfigurationSaveMode.Modified);
                System.Configuration.ConfigurationManager.RefreshSection(_appSettringName);

                this.DialogResult = System.Windows.Forms.DialogResult.OK;
            }
        }
    }
}
